"""
20234-11-28 F 从飞书拉取任务群里的消息

"""

import json
import time
import datetime
from loguru import logger
import re
from dateutil import parser
import requests


import lark_oapi as lark
from lark_oapi.api.im.v1 import *
from top.wardyan.core.wdb.core.DBPool import POOL
from config.Config import *

from lark_oapi.api.auth.v3 import CreateTenantAccessTokenRequest, CreateTenantAccessTokenRequestBody  # 导入 CreateTenantAccessTokenRequest



SQL_FINDUSER = "exec yp_feishu_finduser @pMan='%s'"
SQL_SAVEUSER = "exec yp_feishu_saveuser @pMan='%s',@pName='%s'"
SQL_CLEANDATEMAN = "exec yp_feishu_cleandateman @pDate='%s', @pMan='%s'"
SQL_TASK = "exec yp_feishu_task @pDate='%s', @pMan='%s', @pName='%s',@pIsOK=%d,@pCust='%s',@pTaskID=%d,@pHour=%s,@pUpdateTime='%s',@pCode='%s'"
SQL_GETPREMSGTIME = "exec yp_feishu_getpremsgtime"

APPID = getconfig_str("feishu", "app_id")
APPSECRET = getconfig_str("feishu", "app_secret")
CONTAINERID = getconfig_str("feishu", "container_id")
TOKEN_URL = "https://open.feishu.cn/open-apis/auth/v3/tenant_access_token/internal"

def token_request():
    token_json = {
        "app_id": APPID,
        "app_secret": APPSECRET
    }
    token_res = requests.post(TOKEN_URL, json=token_json)
    token_json = token_res.json()
 
    if token_res.status_code == 200 and token_json.get("code") == 0:
        return token_json.get('tenant_access_token')
    else:
        return None

print(token_request())